import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'result.dart';
class RecordDetailPage extends StatefulWidget {
  RecordDetailPage({Key key, this.title, this.para,this.customer}) : super(key: key);
  final String title;
  final Map<String, dynamic> para;
  final Map<String, dynamic> customer;
  @override
  _RecordDetailPage createState() => _RecordDetailPage();
}

class _RecordDetailPage extends State<RecordDetailPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(widget.customer);
    dataList = [
      {"key":"姓名:","value":widget.customer["visitor_name"].toString()},
      {"key":"證件：","value":widget.customer["visitor_id"].toString()},
      {"key":"到訪原因：","value":"xxx"},
      {"key":"到訪單位：","value":widget.customer["rooms"].toString()},
      {"key":"到訪時間","value":widget.customer["visit_date"].toString()}];
  }

  List<Map<String, String>> dataList = [];
  @override
  Widget build(BuildContext context) {
    List<TableRow> cards = [];
    dataList.asMap().forEach((i, v) {
      cards.add(TableRow(children: <Widget>[
        TableCell(child: Padding(child: Text(v["key"],style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),padding: EdgeInsets.only(left: 100,top: 10,bottom: 10),)),
        TableCell(child: Padding(child: Text(v["value"],style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),padding: EdgeInsets.only(left: 100,top: 10,bottom: 10),)),
      ]));

    });
    return Scaffold(
      appBar: AppBar(
          title: Text(widget.title),
          actions: <Widget>[
            FlatButton(
              child: Text("登出",style: TextStyle(color: Colors.white),),
              onPressed: () {
                Navigator.of(context).popUntil((route) => route.settings.name == "MyHome2Page");
              },
            )
          ]
      ),
      body: Column(
        children: <Widget>[
          // Text("當值職員"),
          // SizedBox(
          //   height: 20,
          // ),
          Container(child: Table(children: cards,columnWidths: {0:IntrinsicColumnWidth(flex: 1),1:IntrinsicColumnWidth(flex: 2)},)),
          MaterialButton(
            materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
            height: 40,
            minWidth: 200,
            padding: EdgeInsets.all(0),
            color: Color(0xff4a701e),
            textColor: Colors.white,
            shape: RoundedRectangleBorder(
                borderRadius:
                BorderRadius.all(Radius.circular(10))),
            onPressed: () {
              var dic = widget.para;
              Navigator.push( context, MaterialPageRoute(builder: (context) => ResultPage(title: widget.title,para: dic)),);
            },
            child: Text("核實並提交"),
          )
        ],
      ),
    );
  }
}

